home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8058 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.9 KB

  1. Path: s02.pavilion.co.uk!usenet
  2. From: AJRobb@pavilion.co.uk (Andy J Robb)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP..Need to find why atan2 gives..
  5. Date: Fri, 01 Mar 1996 06:37:25 GMT
  6. Organization: Pavilion Internet plc
  7. Message-ID: <4h65tu$2mr@s02.pavilion.co.uk>
  8. References: <Pine.OSF.3.91.960201012731.27628B-100000@reno.WPI.EDU>
  9. NNTP-Posting-Host: poolc53.pavilion.co.uk
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Jose Andres Giraldez <vittohue@wpi.edu> wrote:
  13.  
  14. >I need to find why atan2 gives a number smaller than -180 and greater 
  15. >than 180.
  16. >??????????
  17.  
  18. >/*It works on BIGWPI.wpi.edu*/
  19. >#include <stdio.h>
  20. >#include <float.h>
  21. >#include <math.h>
  22. >#include "/cs/cs1005/problems/problem2/problem2.h"
  23. >int main ()
  24. >{
  25. >  int Pi=3.14159, count, n_rows, n_columns;
  26.  
  27. Pi should not be int
  28.  
  29. try:
  30.  
  31.    const double Pi = atan(1.0)*4;
  32.  
  33. >  float limit;
  34. >  float temporary;
  35.  
  36. >  double degrees[N_MEAS];
  37. >  double min_rad_deri;
  38. >  double max_rad_deri;
  39. >  double derivation[N_MEAS];
  40. >  double theta[N_MEAS];
  41. >  double radius[N_MEAS];
  42. >  double AvgRadius;
  43. >  double radius_sum;     /* This will find the sum of ALL the radius */
  44.  
  45.  
  46. >  /*Set loop for all N_MEAS*/
  47. >  for (count = 0; count < N_MEAS; count++)
  48. >    {
  49.  
  50. >      /*Find all values for theta*/
  51. >      radius[count] = sqrt((x[count] * x[count]) + (y[count] * y[count]));
  52.  
  53. >      /*Find all values fors radius*/
  54. >      theta[count] = atan2(y[count], x[count]);
  55.  
  56. >      printf("Here is r: %f and theta: %f\n",  radius[count],  theta[count]);
  57.  
  58. >      /*Find the Sum of all the Radi*/
  59. >      radius_sum = radius_sum + radius[count];
  60.  
  61. >      /*Use the float.h to see if the radius growing is a problem*/
  62. >      /*printf("DEBUG: %f\n", DBL_MAX - radius_sum);*/
  63. >      /*THe radius_sum is fine*/
  64. >    }
  65. >  /*Find the AVG Radius*/
  66.  
  67. >  if (radius_sum <0)
  68. >    {
  69. >      radius_sum = radius_sum * -1;
  70. >    }
  71. >  else
  72. >    {
  73. >      AvgRadius = (float) radius_sum / N_MEAS;
  74. >      printf("This is the AVG Radius: %f\n",AvgRadius);
  75. >    }
  76.  
  77. >  /*Find the deviations from the avg radius*/
  78. >  for (count=0; count < N_MEAS; count++)
  79. >     { 
  80. >      derivation[count] = (float) AvgRadius - radius[count];
  81. >      /*printf("THese are the derivations: %f\n",derivation[count]);*/
  82. >    }
  83. >  /*Convert theta from radians to degrees*/
  84. >  {
  85. >    for (count = 0; count<N_MEAS; count++)
  86. >      {
  87. >        degrees[count] =  (double) ((theta[count] * 180)/Pi)+Pi;
  88.  
  89. Why do you add Pi (i.e. radians) to a value that is now in degrees?
  90.  
  91. >        printf("THese are the degrees: %f\n",degrees[count]);
  92. >      }
  93. >  }
  94. >  /*Find the maximum and minimum for the y-axis*/
  95. >  {  
  96. >    float min_rad_deri = 80.0;
  97. >    float max_rad_deri = 0.0;
  98. >    float temporary;
  99. >    for(count= 0; count<N_MEAS; count++)
  100. >      {
  101. >        temporary=derivation[count];
  102. >        if (min_rad_deri > temporary)
  103. >          { 
  104. >            min_rad_deri = temporary;
  105. >          }
  106. >        temporary=derivation[count];
  107. >        if (max_rad_deri < temporary)
  108. >          { 
  109. >            max_rad_deri = temporary;
  110. >          }
  111. >      }
  112. >    printf("The minimum derivation from avg radius: %f\n",min_rad_deri);
  113. >    printf("The maximum derivation from avg radius: %f\n",max_rad_deri);
  114. >  }
  115. >      
  116. >  /*Compare the min and max to obtain the limits for the graph*/
  117. >  {  
  118. >    if ((min_rad_deri * -1) > max_rad_deri)
  119. >      {
  120. >        limit = min_rad_deri;
  121. >      }
  122. >    if ((min_rad_deri * -1) < max_rad_deri)
  123. >      {
  124. >        limit = max_rad_deri;
  125. >      }
  126.  
  127. >    /*Design the graph*/
  128. >    {
  129.  
  130. >    }
  131. >  }
  132. >  double degrees =0;
  133. >  double radius=0;
  134. >  double theta=0;
  135.  
  136. >  Pi=3.14159;
  137. Remove this assignment to what I have defined as a const double.
  138.  
  139. >            
  140. >}
  141.  
  142.  
  143. Regards,
  144.  
  145. -----BEGIN PGP PUBLIC KEY BLOCK-----
  146. Version: 2.6.2i
  147.  
  148. mQCNAy/MpRwAAAEEAOt6uBYqT8yv9EmqNhK8m6v+bYi8QjnGW3Bo6iU1gsMj5pa6
  149. MHgq99c8deADbE3cbJ6uZS9v5pZE3WCf6HCQjlB5iULA5RZzMdAumd/WUzuL9UT3
  150. B44D9EqqFIL79FlYb56v4oKFqFp1/J2bIpYUwnUvabGzGjdLrpPl4P16x9sNAAUR
  151. tCNBbmR5IEogUm9iYiA8QUpSb2JiQHBhdmlsaW9uLmNvLnVrPrQhQW5keSBSb2Ji
  152. IDxBSlJvYmJAcGF2aWxpb24uY28udWs+
  153. =/wVD
  154. -----END PGP PUBLIC KEY BLOCK-----
  155.  
  156.